import React, { useState, useEffect } from "react";
import { createNativeStackNavigator } from '@react-navigation/native-stack';
// 单签钱包的组件导入
import Home from "@/pages/home"
import CreatePrompt from "@/pages/create/create-prompt"
import CreateGenerate from "@/pages/create/create-generate"
import CreateCopy from "@/pages/create/create-copy"
import CreateReview from "@/pages/create/create-review"
import RecoveryPrompt from "@/pages/recovery/recovery-prompt"
import VerifyMnemonic from "@/pages/recovery/verify-mnemonic"
import CoinSelect from "@/pages/main/coin/coin-select";
import CoinAdd from "@/pages/main/coin/coin-add";
import Receive from "@/pages/main/receive";
import ShowPrivateKey from "@/pages/main/receive/show-private";
import Send from "@/pages/main/send";
import AddressBook from "@/pages/main/address/address-book";
import AddAddress from "@/pages/main/address/address-book/add-address";
import Assets from "@/pages/main/assets";
import AssetsSettings from "@/pages/main/assets/settings";
import ResetPassword from "@/pages/reset-password";
import AddressManage from "@/pages/main/address";
//多签钱包的组件导入
import SectokenHaveAccount from "@/pages/safe/home/have-safe-account"
import SectokenNoAccount from "@/pages/safe/home/no-safe-account"
import SectokenCreate from "@/pages/safe/create"
import SectokenPayWith from "@/pages/safe/create/pay-with"
import SectokenNetWorkFee from "@/pages/safe/create/network-fee"
import SectokenMain from "@/pages/safe/main"
import SectokenImport from "@/pages/safe/import"
import SectokenImportName from "@/pages/safe/import/enter-name"
import SectokenAccountChange from "@/pages/safe/main/account-change"
import SectokenAccountSetting from "@/pages/safe/main/account-setting"
import SectokenAccountSettingEdit from "@/pages/safe/main/account-setting/edit-name"
import SectokenSendSelectAsset from "@/pages/safe/main/send"
import SectokenSendInfo from "@/pages/safe/main/send/send-info"
import SectokenSendReview from "@/pages/safe/main/send/send-review"
import SectokenSendSelectOwner from "@/pages/safe/main/send/send-owner"
import SectokenSendResult from "@/pages/safe/main/send/send-result"
import SectokenSendGeneralDetail from "@/pages/safe/main/send/send-detail/general-detail"
import SectokenSendCreationDetail from "@/pages/safe/main/send/send-detail/creation-detail"
import SectokenSendRejectionDetail from "@/pages/safe/main/send/send-detail/rejection-detail"
import SectokenSendReceiveDetail from "@/pages/safe/main/send/send-detail/receive-detail";
import SectokenSendExecute from "@/pages/safe/main/send/send-execute"
import SectokenTranscation from "@/pages/safe/main/transcation"
import { getValue } from "@/utils/deviceStorage";
import BottomTabNavigator from './BottomTabNavigator'

const Stack = createNativeStackNavigator();

const StackNavigator = () => {

    const [initialRouteName, setInitialRouteName] = useState('')

    useEffect(() => {
        let result = getValue('mnemonicStr')
        if (result) {
            setInitialRouteName('main')
        } else {
            setInitialRouteName('home')
        }
    }, []);

    const Layout = (initialRouteName) => {
        if (initialRouteName) {
            return (
                <Stack.Navigator initialRouteName={initialRouteName}>
                    {/* 单签wallet路由配置 */}
                    <Stack.Screen name='home' component={Home} options={{ headerShown: false }} />
                    <Stack.Screen name='main' component={BottomTabNavigator} options={{ headerShown: false }} />
                    <Stack.Screen name='create-prompt' component={CreatePrompt} options={{ headerShown: false }} />
                    <Stack.Screen name='create-generate' component={CreateGenerate} options={{ headerShown: false }} />
                    <Stack.Screen name='create-copy' component={CreateCopy} options={{ headerShown: false }} />
                    <Stack.Screen name='create-review' component={CreateReview} options={{ headerShown: false }} />
                    <Stack.Screen name='recovery-prompt' component={RecoveryPrompt} options={{ headerShown: false }} />
                    <Stack.Screen name='verify-mnemonic' component={VerifyMnemonic} options={{ headerShown: false }} />
                    <Stack.Screen name='coin-select' component={CoinSelect} options={{ headerShown: false }} />
                    <Stack.Screen name='coin-add' component={CoinAdd} options={{ headerShown: false }} />
                    <Stack.Screen name='receive' component={Receive} options={{ headerShown: false }} />
                    <Stack.Screen name='show-private-key' component={ShowPrivateKey} options={{ headerShown: false }} />
                    <Stack.Screen name='send' component={Send} options={{ headerShown: false }} />
                    <Stack.Screen name='address-book' component={AddressBook} options={{ headerShown: false }} />
                    <Stack.Screen name='add-address' component={AddAddress} options={{ headerShown: false }} />
                    <Stack.Screen name='assets' component={Assets} options={{ headerShown: false }} />
                    <Stack.Screen name='assets-settings' component={AssetsSettings} options={{ headerShown: false }} />
                    <Stack.Screen name='reset-pwd' component={ResetPassword} options={{ headerShown: false }} />
                    <Stack.Screen name='address-manage' component={AddressManage} options={{ headerShown: false }} />
                    {/* 多签safe-wallet路由配置 */}
                    <Stack.Screen name='safe-no-account' component={SectokenNoAccount} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-have-account' component={SectokenHaveAccount} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-create' component={SectokenCreate} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-create-pay-with' component={SectokenPayWith} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-create-net-fee' component={SectokenNetWorkFee} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-main' component={SectokenMain} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-import' component={SectokenImport} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-import-name' component={SectokenImportName} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-account-setting' component={SectokenAccountSetting} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-account-change' component={SectokenAccountChange} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-account-setting-edit' component={SectokenAccountSettingEdit} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-send-asset' component={SectokenSendSelectAsset} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-send-info' component={SectokenSendInfo} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-send-review' component={SectokenSendReview} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-send-owner' component={SectokenSendSelectOwner} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-send-result' component={SectokenSendResult} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-general-detail' component={SectokenSendGeneralDetail} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-creation-detail' component={SectokenSendCreationDetail} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-rejection-detail' component={SectokenSendRejectionDetail} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-receive-detail' component={SectokenSendReceiveDetail} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-send-execute' component={SectokenSendExecute} options={{ headerShown: false }} />
                    <Stack.Screen name='safe-transcation' component={SectokenTranscation} options={{ headerShown: false }} />
                </Stack.Navigator>
            )
        } else {
            return <></>;
        }
    }

    return (
        <>
            {Layout(initialRouteName)}
        </>
    );
};

export default StackNavigator;

